package com.niit.session23;
//创建线程的方式2：如果一个类已经继承了别的接口，就可以让这个类实现Runnable接口
public class ThreadDemo1 implements Runnable{
	
	public static void main(String[] args) {
//		Runnable里面没有start方法，所以需要通过实例化一个Thread类，然后把Runnable的实例传进去创建这个线程
		ThreadDemo1 threadDemo1 = new ThreadDemo1();
		Thread thread = new Thread(threadDemo1);
//		设置线程的优先级
		thread.setPriority(Thread.MAX_PRIORITY);
		thread.start();
		
		for (int i = 1; i <= 1000; i++) {
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("主线程==》"+i);
		}
		
	}
	
	@Override
	public void run() {
		for (int i = 1; i <= 1000; i++) {
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("子线程-->"+i);
		}
	}

}
